<?php

namespace Vavilen\FirstBundle\DataFixtures\ORM;

use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\DataFixtures\FixtureInterface;
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
use Doctrine\Common\Persistence\ObjectManager;
use Vavilen\FirstBundle\Entity\Post;

class LoadPostData extends AbstractFixture implements OrderedFixtureInterface, FixtureInterface
{
	public function load(ObjectManager $manager)
	{
		$content = 'Lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum
			 lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum';

		$post1 = new Post();
		$post1->setCategory($manager->merge($this->getReference('news')));
		$post1->addTag($manager->merge($this->getReference('math')));
		$post1->setUser($manager->merge($this->getReference('role_admin')));
		$post1->setTitle('Пост-1');
		$post1->setDescription('Описание поста');
		$post1->setContent($content);
		$manager->persist($post1);

		$post2 = new Post();
		$post2->setCategory($manager->merge($this->getReference('bulk')));
		$post2->addTag($manager->merge($this->getReference('math')));
		$post2->addTag($manager->merge($this->getReference('alg')));
		$post2->setUser($manager->merge($this->getReference('role_user')));
		$post2->setTitle('Пост-2');
		$post2->setDescription('Описание поста');
		$post2->setContent($content);
		$manager->persist($post2);

		$post3 = new Post();
		$post3->setCategory($manager->merge($this->getReference('karton')));
		$post3->addTag($manager->merge($this->getReference('math')));
		$post3->addTag($manager->merge($this->getReference('alg')));
		$post3->addTag($manager->merge($this->getReference('Geo')));
		$post3->setUser($manager->merge($this->getReference('role_user')));
		$post3->setTitle('Пост-3');
		$post3->setDescription('Описание поста');
		$post3->setContent($content);
		$manager->persist($post3);

		$manager->flush();
	}

	public function getOrder()
	{
		return 4;
	}
}